//
//  ArtManager.m
//  EasyToo
//
//  Created by zhengzhe on 13-8-25.
//
//

#import "ArtManager.h"
#import "ServerCommunicationManager.h"

#import "QryAllArtInfoRequest.h"
#import "QryAllArtInfoResponse.h"

#import "BuyArtTicketRequest.h"
#import "BuyArtTicketResponse.h"

#import "ConfirmArtTicketRequest.h"
#import "ConfirmArtTicketResponse.h"


@implementation ArtManager

static ArtManager* gManager = nil;


+ (ArtManager*)shareManager
{
    if (gManager == nil) {
        gManager = [[ArtManager alloc] init];
    }
    return gManager;
}

//查询所有演艺票
- (void)qryAllArtInfo
{
    QryAllArtInfoRequest *request = [[QryAllArtInfoRequest alloc] initQryAllSiteInfo:self];
    [[ServerCommunicationManager GetServerCommunication] sendRequest:request];
}

//购买演艺票
- (void)buyArtInfo:(NSString*)quantity
       singlePrice:(NSString*)singlePrice
            mobile:(NSString*)mobile
      customerName:(NSString*)customerName
           priceId:(NSString*)priceId
{
    BuyArtTicketRequest *request = [[BuyArtTicketRequest alloc] initBuyArtTicketInfo:self
                                                                            quantity:quantity
                                                                         singlePrice:singlePrice
                                                                              mobile:mobile
                                                                        customerName:customerName
                                                                             priceId:priceId];
    [[ServerCommunicationManager GetServerCommunication] sendRequest:request];
 
}

//确认购买门票
- (void)confirmBuyArtTicket:(NSString*)agentOrderID
                   amount:(NSString*)amount
              projectName:(NSString*)projectName
                    phone:(NSString*)phone
                 allPrice:(int)allPrice
{
    ConfirmArtTicketRequest *request = [[ConfirmArtTicketRequest alloc] confirmBuyArtTicket:self
                                                                           agentOrderID:agentOrderID
                                                                                 amount:amount
                                                                            projectName:projectName
                                                                                  phone:phone
                                                                               allPrice:allPrice];
    
    [[ServerCommunicationManager GetServerCommunication] sendRequest:request];
}


- (void)onRequestSuccess:(BaseResponse *)response
{
    if ([response isKindOfClass:[QryAllArtInfoResponse class]])
    {
        [self handleQryAllArtInfoSuccess:(QryAllArtInfoResponse*)response];
    }
    else if ([response isKindOfClass:[BuyArtTicketResponse class]])
    {
        [self handlebuyArtInfoSuccess:(BuyArtTicketResponse*)response];
    }
    else if ([response isKindOfClass:[ConfirmArtTicketResponse class]])
    {
        [self handleconfirmArtInfoSuccess:(ConfirmArtTicketResponse*)response];
    }
}

- (void)onRequestFail:(BaseResponse *)response
{
    if ([response isKindOfClass:[QryAllArtInfoResponse class]])
    {
        [self.delegate qryAllArtInfo:NO artInfo:nil];
    }
    else if ([response isKindOfClass:[BuyArtTicketResponse class]])
    {
        [self.delegate buyArtInfo:NO OrderId:nil SumPrice:nil];
    }
    else if ([response isKindOfClass:[ConfirmArtTicketResponse class]])
    {
        [self.delegate confirmArtInfo:NO tn:nil];
    }
}


//查看所有演艺票
- (void)handleQryAllArtInfoSuccess:(QryAllArtInfoResponse*)response
{
    AllArtInfo *artInfoArray = response.artArray;
    if (artInfoArray)
    {
        [self.delegate qryAllArtInfo:YES artInfo:artInfoArray];
    }
    else
    {
        [self.delegate qryAllArtInfo:NO artInfo:nil];
    }
}

//购买门票
- (void)handlebuyArtInfoSuccess:(BuyArtTicketResponse*)response
{
    NSString *OrderId = response.OrderId;
    NSString *SumPrice = response.SumPrice;
    if (OrderId)
    {
        [self.delegate buyArtInfo:YES OrderId:OrderId SumPrice:SumPrice];
    }
    else
    {
        [self.delegate buyArtInfo:NO OrderId:nil SumPrice:nil];
    }
}

//确认购买门票
- (void)handleconfirmArtInfoSuccess:(ConfirmArtTicketResponse*)response
{
    NSString *tn = response.tn;
    if (tn)
    {
        [self.delegate confirmArtInfo:YES tn:tn];
    }
    else
    {
        [self.delegate confirmArtInfo:NO tn:nil];
    }
}

@end
